package com.iot08.api.controller;

import com.iot08.api.controller.base.BaseController;
import com.iot08.api.service.SmsNotifyServerService;
import com.iot08.api.service.SmsService;
import com.iot08.api.vo.request.SendSmsNotifyReqVo;
import com.iot08.api.vo.request.SmsNotifyServerAddEditReqVo;
import com.iot08.api.vo.request.base.BaseAccountReqVO;
import com.iot08.common.utils.response.ResponseMap;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * @author cwj
 * @description
 * @date 2025/3/16 15:07
 **/
@Slf4j
@RestController
@RequestMapping("getway/smsNotify")
public class SmsNotifyServerController extends BaseController {

    @Resource
    private SmsNotifyServerService smsNotifyServerService;

    @Resource
    private SmsService smsService;


    /**
     * @description 查询短信通知套餐服务
     * @author cwj
     * @param [vo]
     * @return com.iot08.common.utils.response.ResponseMap
     * @date @time 2025/3/16 16:01
     **/
    @GetMapping("/query")
    public ResponseMap querySmsNotifyServer(@Validated BaseAccountReqVO vo){
        return smsNotifyServerService.querySmsNotifyServer();
    }

    /**
     * @description 新增短信通知服务
     * @author cwj
     * @param [vo]
     * @return com.iot08.common.utils.response.ResponseMap
     * @date @time 2025/3/17 16:16
     **/
    @PostMapping("/add")
    public ResponseMap addSmsNotifyServer(@Validated @RequestBody SmsNotifyServerAddEditReqVo vo){
        return smsNotifyServerService.addSmsNotifyServer(vo);
    }


    /**
     * @description 编辑短信通知设备
     * @author cwj
     * @param [vo]
     * @return com.iot08.common.utils.response.ResponseMap
     * @date @time 2025/3/17 16:16
     **/
    @PostMapping("/edit")
    public ResponseMap editSmsNotifyServer(@Validated @RequestBody SmsNotifyServerAddEditReqVo vo){
        return smsNotifyServerService.editSmsNotifyServer(vo);
    }


    /**
     * @description 测试发送通知短信
     * @author cwj
     * @param [vo]
     * @return com.iot08.common.utils.response.ResponseMap
     * @date @time 2025/3/19 12:00
     **/
    @PostMapping("/sendSmsNotify")
    public ResponseMap sendSmsNotify(@Validated @RequestBody SendSmsNotifyReqVo vo) {
        return smsService.sendNotify(vo.getPhoneNum(),vo.getTemplateType(),vo.getTemplateVariable(),vo.getTemplateVariableName())?ResponseMap.success():ResponseMap.fail("通知发送失败");
    }
}
